package cn.tedu.charging.cost.dao.repository.impl;

import cn.tedu.charging.cost.dao.repository.RedisCostRuleRepository;
import cn.tedu.charging.cost.pojo.po.CostRulePO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class RedisCostRuleRepositoryImpl implements RedisCostRuleRepository {

    @Autowired
    private RedisTemplate<String,List<CostRulePO>> redisTemplate;

    @Override
    public List<CostRulePO> getCostRuleFromRedis(Integer stationId) {
        String key="COST_RULE_KEY_"+stationId;
        ValueOperations<String, List<CostRulePO>> valueOperations = redisTemplate.opsForValue();
        return valueOperations.get(key);
    }

    @Override
    public void saveCostRule2Redis(Integer stationId, List<CostRulePO> dbCostRules) {
        // 保存到redis
        String key="COST_RULE_KEY_"+stationId;
        ValueOperations<String, List<CostRulePO>> valueOperations = redisTemplate.opsForValue();
        valueOperations.set(key,dbCostRules);
    }
}
